home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / net / spakparnet_0_5.lha / han / thing / act_open_new.c < prev    next >
C/C++ Source or Header  |  1992-11-09  |  6KB  |  196 lines

  1. /********************************************************************
  2.  ** NETWORK FILESYSTEM - DOS HANDLER
  3.  **
  4.  ** (c) Spak, Darrell Tam, c9107253@ee.newcastle.edu.au (1994)
  5.  ** phone (Australia) 049-829-710
  6.  **                   +49-829-710
  7.  ** (c) SST 1994
  8.  **
  9.  ** OPEN (ACTION_FINDINPUT | ACTION_FINDOUTPUT | ACTION_UPDATE)
  10.  **
  11.  ** Actions are sent to the network device
  12.  **
  13.  ** NOW supports shells on CON: type devices, 
  14.  ** passes on the first "Open", consequent ones are simply ignored
  15.  ** and returned with the same fh_Arg1. See interactive.s
  16.  **
  17.  ** TABS to 4
  18.  ********************************************************************/
  19.  
  20. #include "/snd/everything.h"
  21. #include "deadheads.h"
  22. #include "root_protos.h"
  23. #include "globs_protos.h"
  24. #include "xtra_protos.h"
  25. #include "interactive_protos.h"
  26.  
  27. #define OPEN_PKTMSG_SIZE sizeof(struct OpenPktMsg)
  28.  
  29. /** this is just a variation of the "doofus" format */
  30. struct OpenPktMsg {
  31.     struct    DoofusPktMsg    dpm;
  32.  
  33.     struct    NFSOpenFile            openreq;    /* request structure */
  34.     struct    NFSOpenFileReturn    openret;    /* return structure */
  35.     struct    FileArg1            *fa1;
  36. };
  37.  
  38.  
  39.  
  40. /********************************************************************/
  41.     long extract_name(char *name, short name_len, long type)
  42. /********************************************************************
  43. returns the type of file this name actually refers to
  44. ie - if the final file should reside on a remote file system then
  45.      LK_REMOTE is returned
  46.  ********************************************************************/
  47. {
  48. long new_type = type;    /* default to the same type */
  49.  
  50. /** THROW AWAY EVERYTHING BEFORE THE ':' AND A TRAILING '/' */
  51.     if((tmp = find_char(name, ':', name_len) + 1) > 0)
  52.         { name += tmp; name_len -= tmp; }
  53.     if(name_len>0 && name[name_len-1] == '/') name_len--;    /* remove trailing '/' */
  54.  
  55. /** TYPE == LK_ROOT? LOOK FOR A MACHINE - OTHERWISE IT IS A LOCAL FILE */
  56.     if(type == LK_ROOT) {
  57.         
  58.     }
  59. /** TYPE == LK_MACHINE? LOOK FOR MORE */
  60.  
  61. /** TYPE == LK_REMOTE? PUT BACK THE FILE NAME AND EVERYTHING */
  62.  
  63.     return(new_type);
  64. }
  65.  
  66.  
  67. /********************************************************************/
  68. static long handle_openfile_net(struct OpenPktMsg *opm)
  69. /********************************************************************/
  70. {
  71. struct DosPacket *dosmsg = opm->dpm.dp_original;
  72. struct FileHandle *fh = BTOC(dosmsg->dp_Arg1);
  73. struct FileArg1    *fa1 = opm->fa1;
  74.  
  75. { unsigned char tt[100]; spf(tt, 100, "open: res1=%ld, res2=%ld",
  76.         opm->openret.remote_res1, opm->openret.remote_res2); MyPrint(win1, tt); }
  77.  
  78.     dosmsg->dp_Res2 = opm->openret.remote_res2;
  79.     if(opm->dpm.net.pm.smsg.result == PAR_OK &&
  80.         (dosmsg->dp_Res1 = opm->openret.remote_res1) ) {
  81.  
  82.         fa1->remote.remote_ifh    = opm->openret.remote_ifh;
  83.         fa1->remote.majic         = opm->openret.remote_majic;
  84.  
  85.     /** IS THE FILE INTERACTIVE?? IF SO, GIVE IT ANOTHER PORT */
  86.         if(*(long *)&fh->fh_Port = opm->openret.remote_ifh_Port) {
  87.         struct InterPort *imp;
  88.             if(imp = AllocRemember(&fa1->mem,
  89.                         INTER_MSGPORT_SIZE, MEMF_PUBLIC | MEMF_CLEAR)) {
  90.                 imp->i.is_Code             = handle_interactive_stuff;
  91.                 imp->i.is_Data             = imp;
  92.                 imp->mp.mp_Node.ln_Type    = NT_MSGPORT;
  93.                 imp->mp.mp_Flags        = PA_SOFTINT;
  94.                 imp->mp.mp_SigTask        = (struct Task *)&imp->i;
  95.                 NewList(&imp->mp.mp_MsgList);
  96.                 imp->fa1 = fa1;
  97.                 imp->pass = localrepport;
  98.                 imp->opencount = 1;
  99.                 dosmsg->dp_Port = imp;            /* new port for every interactive */
  100.             }
  101.         }
  102.         fh->fh_Type = dosmsg->dp_Port;            /* already contains "OurPort" */
  103.         fh->fh_Arg1 = (long)fa1;
  104.     }
  105.  
  106. /** ERROR ??? */
  107.     else {
  108.         REMOVE_FROM_LIST(fa1, first_fa1);        /* no longer open */
  109.         FreeMem(fa1, FA1_SIZE);                    /* gone */
  110.         dosmsg->dp_Res1 = 0;
  111.         if(opm->dpm.net.pm.smsg.result != PAR_OK) dosmsg->dp_Res2 = ERROR_NO_DISK;
  112.     }
  113.     return(AR_FLAG_RETURNDOSMSG | AR_FLAG_FREEDOOF);
  114. }
  115.  
  116.  
  117.  
  118. /********************************************************************/
  119. long action_openfile(struct DosPacket *dosmsg,
  120.                             struct MsgPort *dm_retport)
  121. /********************************************************************/
  122. {
  123. unsigned char *fname = BTOC(dosmsg->dp_Arg3);    /* note, BCPL style string */
  124. short    server;
  125.  
  126. { unsigned char tt[60]; spf(tt,60,"fh=%lx, lock=%lx, task=%lx",
  127.         dosmsg->dp_Arg1, dosmsg->dp_Arg2, dosmsg->dp_Port->mp_SigTask);
  128.         MyPrint(win1, tt); }
  129.  
  130. /** IF THERE IS A LOCK */
  131.     if(dosmsg->dp_Arg2) {
  132.         dosmsg->dp_Res1 = 0; dosmsg->dp_Res2 = ERROR_OBJECT_NOT_FOUND;
  133.         return(AR_FLAG_RETURNDOSMSG);
  134.     }
  135.     else if(fname[0] == 1 && fname[1] == '*') {
  136.         dosmsg->dp_Res1 = 0; dosmsg->dp_Res2 = ERROR_OBJECT_NOT_FOUND;
  137.         return(AR_FLAG_RETURNDOSMSG);
  138.     }
  139.  
  140. /** CHECK OUT THE FILE NAME */
  141.     MyPrintBCPL(win1,dosmsg->dp_Arg3);
  142.  
  143.     server = fname[6]-'0';
  144.     if(fname[5] == ',' && server >=0 && server<=9 &&
  145.                                 fname[0] > 7 && netservport[server]) {
  146.     struct OpenPktMsg    *opm;
  147.     struct FileArg1        *fa1;
  148.     unsigned char        *send_name;
  149.     short    send_name_len = fname[0] - 7+2;
  150.  
  151.         if(!(fa1 = AllocMem(FA1_SIZE, MEMF_PUBLIC)) ||
  152.            !(opm = AllocMem(OPEN_PKTMSG_SIZE + send_name_len, MEMF_PUBLIC)) ) {
  153.             FreeMem(fa1, FA1_SIZE);
  154.             dosmsg->dp_Res1 = 0; dosmsg->dp_Res2 = ERROR_NO_FREE_STORE;
  155.             return(AR_FLAG_RETURNDOSMSG);
  156.         }
  157.  
  158.         opm->fa1 = fa1;
  159.  
  160.         send_name        = (unsigned char *)&opm[1];
  161.         send_name[0]    = fname[0] - 7;
  162.         spf(&send_name[1], send_name_len-1, &fname[8]);
  163.  
  164.         opm->openreq.request     = REQUEST_OPENFILE;
  165.         opm->openreq.action     = dosmsg->dp_Type;
  166.         opm->openreq.internallock = NULL;                /* for the moment */
  167.  
  168.         ADD_HEAD(fa1, first_fa1);                        /* add into the list */
  169.         fa1->Type        = LK_REMOTE;
  170.         fa1->fh         = BTOC(dosmsg->dp_Arg1);        /* (don't really use it tho) */
  171.         fa1->parent_lock = BTOC(dosmsg->dp_Arg2);        /* lock we're from */
  172.         fa1->mem        = NULL;
  173.  
  174.         INIT_DOOFPKTMSG(&opm->dpm,
  175.                     handle_openfile_net,
  176.                     netrepport,
  177.                     fa1->fsys = netservport[server],
  178.                     dosmsg,
  179.                     dm_retport,
  180.                     OPEN_PKTMSG_SIZE+send_name_len,
  181.                     fa1->remote.machine = fname[7],
  182.                     fa1->remote.service = SERV_FILE,
  183.                     &opm->openreq, sizeof(struct NFSOpenFile),    /* request */
  184.                     send_name, send_name_len,                    /* send-body */
  185.                     NULL, 0,                                    /* result-body */
  186.                     &opm->openret, sizeof(struct NFSOpenFileReturn));
  187.                                                                 /* return codes */
  188.     { unsigned char tt[100]; spf(tt, 100, "port=%lx", opm->dpm.net.server); MyPrint(win1, tt); }
  189.  
  190.         PutMsg(opm->dpm.net.server, opm);
  191.         return(0);
  192.     }
  193.     dosmsg->dp_Res1 = 0; dosmsg->dp_Res2 = ERROR_OBJECT_NOT_FOUND;
  194.     return(AR_FLAG_RETURNDOSMSG);
  195. }
  196.